#include "util/string_helper.h"

namespace util {

uint32 StrToInt(const std::string& str) {
  uint32 i = 0;
  for (size_t pos = 0; pos != str.size(); ++pos) {
    i = i * 10 + str[pos] - '0';
  }

  return i;
}

const std::string IntToStr(uint32 i) {
  std::string str;
  while (i > 0) {
    uint32 j = i % 10;
    str.insert(0, 1, '0' + j);
    i /= 10;
  }

  return str;
}

void SplitStringByChar(const std::string& str, char split,
                       std::vector<const std::string>* vec) {
  std::string::iterator beg = str.begin();
  std::string::iterator end = str.end();
  std::string::iterator it;
  while ((it = std::find(beg, end, split)) != end) {
    vec->push_back(str.substr(beg - str.begin(), it - beg));

    beg = ++it;
  }
}

}
